/**
 * 
 * 广州锐鹏计算机科技有限公司（www.ruipengkj.com）
 * 
 * 
 * Copyright (c) 2011-2012 RUIPENGKJ.Co.Ltd. All rights reserved.
 * 
 * */
package com.ruipengkj.view;
/**
 * 说明：
 * 添加仓库界面
 * @Author：黄盛强
 * @Date：2012-03-20
 */
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

import com.ruipengkj.bean.TStore;
import com.ruipengkj.commons.BuildSpringApplication;
import com.ruipengkj.commons.util.Util;
import com.ruipengkj.component.JLabelJTextFieldComponent;
import com.ruipengkj.service.TStoreService;
import com.ruipengkj.view.base.BaseDialog;


public class AddDataStorageDialog extends BaseDialog implements ActionListener {

	private static final long serialVersionUID = 1L;

	private JLabelJTextFieldComponent name;
	private JLabelJTextFieldComponent location;
	private JLabelJTextFieldComponent manager;
	private JLabelJTextFieldComponent note;
	
	private JButton sureButton;
	private JButton cancelButton;
	
	private TStore tStore = null;
	private TStoreService storeService;
	public boolean isSuccess=false;//判断是否添加成功
	public AddDataStorageDialog(JFrame jf,String title,boolean b) {
		super(jf, title, b);
		this.setSize(400, 200);
		this.setLayout(new GridLayout(3, 1));
		this.init();
		this.setLocationRelativeTo(null);
		this.setVisible(true);
	}
	
	public void init() {
		storeService=BuildSpringApplication.getInstance().getTStoreServiceImpl();
		name = new JLabelJTextFieldComponent("  仓库名称：", 15);
		location = new JLabelJTextFieldComponent("  仓库地址：", 15);
		manager = new JLabelJTextFieldComponent("仓库管理员：", 15);
		note = new JLabelJTextFieldComponent("  备    注：", 15);
		
		sureButton = new JButton("确定");
		cancelButton = new JButton("取消");
		
		sureButton.addActionListener(this);
		cancelButton.addActionListener(this);
		
		JPanel p1 = new JPanel();
		p1.add(name);
		p1.add(location);
		
		JPanel p2 = new JPanel();
		p2.add(manager);
		p2.add(note);
		
		JPanel p3 = new JPanel();
		p3.add(sureButton);
		p3.add(cancelButton);
		
		add(p1);
		add(p2);
		add(p3);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getSource() == sureButton) {
			if("".equals(name.getText().getText().trim())||"".equals(location.getText().getText().trim())||"".equals(location.getText().getText().trim())||"".equals(location.getText().getText().trim())){
				Util.showMessageDialog("所有信息不能为空！");
			}else{
				tStore = new TStore();
				tStore.setName(name.getText().getText().trim());
				tStore.setLocation(location.getText().getText().trim());
				tStore.setManager(manager.getText().getText().trim());
				tStore.setNote(note.getText().getText().trim());
				try {
					this.storeService.saveService(tStore);
					this.isSuccess=true;
				} catch (Exception e1) {
					e1.printStackTrace();
					this.isSuccess=false;
				}
				this.dispose();
			}
		} else if(e.getSource() == cancelButton) {
			this.isSuccess=false;
			this.dispose();
		}
	}
}
